<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<link rel="stylesheet" href="../static/css/common/reset.min.css" />
		<link rel="stylesheet" href="../static/css/common/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../static/css/order/select_fuyou.css" />
		<title>还款详情</title>
	</head>

	<body>
		<div class="body">
			<ul>
				<li>
					<span>还款总额</span>
					<span class="red"></span>
				</li>
				<li>
					<span>姓名:</span>
					<span class="name"></span>
				</li>
				<li>
					<span>银行卡号：</span>
					<input type="text" class="number" placeholder="请输入银行卡号" value="" />
				</li>
				<div class="bank_error"></div>
				<li>
					<span>所属银行：</span>
					<span class="bank"></span>
				</li>
			</ul>
			<div class="enter">
				<button>确认还款</button>
			</div>
		</div>

		<div id="myModal" style="display:none">
			<img src="../static/img/loading.png">
		</div>

		<form name="forwardForm" action="" method="POST" style="display: none;">
			<input type="hidden" name="ENCTP" value="" />
			<input type="hidden" name="MCHNTCD" value="" />
			<input type="hidden" name="FM" value="" />
			<input type="hidden" name="VERSION" value="" />
			<input type="hidden" name="LOGOTP" value="" />
		</form>
	</body>
	<script src="../static/js/common.js?v=1"></script>
	<script src="../static/js/bridge.js"></script>
	<script src="../static/js/common/jquery.min.js"></script>
	<script type="text/javascript" src="../static/js/common/mui.min.js"></script>
	<script>
		//防止安卓回退到之前页面
		if(sessionStorage.getItem("flag") == 1) {
			sessionStorage.removeItem("flag");
			closeAndOpen(0);
		};
		var apiDomain = apiDomain();
		var webDomain = webDomain();
		var orderId = request['orderId'];
		var repayMoney = request['repayMoney'];
		var preclear = request['preclear'];
		$(function() {
			$(".red").html(repayMoney + "元");
			var token = getToken();
			if(!token) {
				closeAndOpen(1);
				return;
			};
			//获取用户名
			$.ajax({
				url: apiDomain + "/bank_user",
				type: "post",
				dataType: "json",
				data: {
					token: token
				},
				success: function(data) {
					if(data.status == 2000) {
						$('.name').text(data.data.name);
					}
				}
			});

			//修改银行卡号
			$(".number").focus(function() {
				$(".bank_error").hide();
			});
			$(".number").blur(function() {
				var val = $(this).val();
				if(val == "" || !/^\d{16,19}$/.test(val)) {
					$(".bank_error").hide();
				};
			});
			$(".number").on('input', function() {
				$(".bank_error").html("");
				var cardNo = $(".number").val();
				if(/^\d{16,19}$/.test(cardNo)) {
					$.ajax({
						url: apiDomain + "bank_name",
						type: "post",
						dataType: "json",
						data: {
							cardNo: cardNo
						},
						success: function(data) {
							if(data.status == 2000) {
								$(".bank").text(data.data);
							} else {
								$(".bank_error").show().text(data.message);
								$(".bank").text("");
							};
						}
					});
				}
			});

			//确认付款
			$(".enter button").click(function() {
				var token = getToken();
				var cardNo = $(".number").val();
				var cardName = $(".bank").html();
				var name = $(".name").html();
				if(!token) {
					closeAndOpen(1);
					return;
				};
				if(cardNo == "" || name == "" || !/^(?!(\s+$))/.test(cardNo)) {
					mui.alert("请输入正确的银行卡号");
					return;
				};
				$.ajax({
					type: "post",
					url: apiDomain + "/order/order_repay_fuyou",
					async: true,
					dataType: "json",
					data: {
						token: token,
						orderId: orderId,
						cardNo: cardNo,
						preclear:preclear,
						cardName: cardName
					},
					beforeSend: function() {
						$('#myModal').show();
					},
					success: function(res) {
						if(res.status == 2000) {
							var datr = res.data;
							sessionStorage.setItem("flag", 1);
							$("form[name='forwardForm']").prop("action", datr.FUIOU_URL);
							$("input[name='ENCTP']").val(datr.ENCTP);
							$("input[name='FM']").val(datr.FM);
							$("input[name='LOGOTP']").val(datr.LOGOTP);
							$("input[name='VERSION']").val(datr.VERSION);
							$("input[name='MCHNTCD']").val(datr.MCHNTCD);
							$("form[name='forwardForm']").submit();
						} else {
							mui.alert(res.message);
						};
					},
					complete: function() {
						$('#myModal').stop().hide();
					}
				});
			});
		});
	</script>

</html>